package com.scau.ums.controller;

import com.github.pagehelper.PageInfo;
import com.scau.ums.mapper.RepairreportMapper;
import com.scau.ums.model.Info;
import com.scau.ums.model.Repairreport;
import com.scau.ums.service.imp.RepairReport.RepairReportImp;
import com.scau.ums.service.imp.info.DefaultSendInfoImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class VerifyRepairReportController {

    @Autowired
    private RepairReportImp repairReportImp;
    @Autowired
    private RepairreportMapper repairreportMapper;
    @Autowired
    private DefaultSendInfoImp defaultSendInfoImp;

    @RequestMapping(value = "/VerifyRepairReport")
    public String VerifyRepairReport(HttpServletRequest request,@RequestParam(value = "currentPage",required=false,defaultValue="1")Integer currentPage){

        List<Repairreport> UnverifiedRepairReports = repairReportImp.getUnverifiedRepairReports(currentPage);
        PageInfo<Repairreport> pageInfo = new PageInfo<Repairreport>(UnverifiedRepairReports);

        request.setAttribute("UnverifiedRepairRepots",UnverifiedRepairReports);
        request.setAttribute("pageInfo",pageInfo);

        return "VerifyRepairReport";
    }

    //这个暂时不需要 by xfy
    @RequestMapping(value = "/SpecifiedReport")
    public  String SpecifiedReport(HttpServletRequest request,int Id){
        Repairreport repairreport = repairreportMapper.selectByPrimaryKey(Id);
        request.setAttribute("repairReport",repairreport);
        return "VerifySpecifiedRepairReport";
    }

    @RequestMapping(value = "/VerifySuccess")
    public String VerifySuccess(Integer RepairReportId){
        repairReportImp.VerifySuccess(RepairReportId);
        Repairreport repairreport = repairreportMapper.selectByPrimaryKey(RepairReportId);
        System.out.println(repairreport);
        Info info=defaultSendInfoImp.createInfo("维修单审核情况","system",repairreport.getReporterid(),repairreport.getReportertype(),"您的关于‘ "+repairreport.getRepairdesc()+" ’的维修情况已受理，敬请等候处理");
        defaultSendInfoImp.sendInfo(info);
        return "redirect:/VerifyRepairReport";
    }

    @RequestMapping(value = "/VerifyFailed")
    public String VerifyFailed(Integer RepairReportId,String remark){
        repairReportImp.VerifyFailed(RepairReportId,remark);
        Repairreport repairreport = repairreportMapper.selectByPrimaryKey(RepairReportId);
        System.out.println(repairreport);
        Info info=defaultSendInfoImp.createInfo("维修单审核情况","system",repairreport.getReporterid(),repairreport.getReportertype(),"您的关于‘ "+repairreport.getRepairdesc()+" ’的维修单被拒绝通过，拒绝理由为："+repairreport.getRemark());
        defaultSendInfoImp.sendInfo(info);
        return "redirect:/VerifyRepairReport";
    }
}
